home *** CD-ROM | disk | FTP | other *** search
- @echo off
- ! delPath.bat Batch file to remove a folder from the PATH
- !
- ! delPath pos
- !
- ! 'pos' is the position within the PATH of the folder to be removed. If
- ! 'pos' is omitted or exceeds the number of folders in the path,
- ! the last folder is removed.
- !
- ! Example:
- ! delPath applied to the initial PATH "first;second;third" will have the
- ! following results:
- ! delPath first;second
- ! delPath 1 second;third
- ! delPath 2 first;third
- ! delPath 3 first;second
- ! delPath 4 first;second;third
- !
- ! Copyright © 1994 by Rainbow Hill Pty Ltd. All rights reserved.
- !
-
- set delPath_saved_path=%PATH%
- set doserr=0
-
- ! determine the position
- if "%1 " == " " goto FROM_END_LBL
- set delPath_pos=%1
- if "%1" == 1 goto FROM_START_LBL
-
- !
- ! scan the existing PATH and skip one folder at a time until you reach
- ! the requested position or until you run out of folders
- !
- set delPath_tail=%PATH%
- :SKIP_ONE_LBL
- if %delPath_pos% == 0 goto POS_FOUND_LBL
- if "%delPath_tail%" == %%delPath_TAIL%% goto FROM_END_LBL
- sstr delPath_tail ; /R
- if %doserr% == 72 goto FROM_END_LBL
- decr delPath_pos
- goto SKIP_ONE_LBL
-
- :FROM_END_LBL
- !
- ! remove the last folder (if any)
- if "%PATH% " == " " goto DONE_LBL
- set doserr=0
- sstr path ; /E/L
- if %doserr% == 72 set path=
- goto DONE_LBL
-
- :FROM_START_LBL
- !
- ! remove the first folder (if any)
- if "%PATH% " == " " goto DONE_LBL
- sstr path ; /R
- if %doserr% == 72 set path=
- goto DONE_LBL
-
- :POS_FOUND_LBL
- !
- ! remove the requested folder (cannot be the first or the last one)
- decr path by "%delPath_tail%"
- decr path by 1
- sstr path ; /E/L
- incr path by ";%delPath_tail%"
- goto DONE_LBL
-
- :ERR_LBL
- show %doserr%
- set path=%delPath_saved_path%
-
- :DONE_LBL
- ! remove the global variables
- set delPath_pos=
- set delPath_tail=
- set delPath_saved_path=
-